﻿using System;
using System.Collections.Generic;
using System.Text;
using AppToolKit.Controller.Macro;
using System.Windows.Forms;

namespace PMSBusiness.Service.Background
{
    public class TaskMacro :MacroBase
    {
        //[AutoWiring]
        //public ICommonService CommonService{get;set;}
        public TaskMacro() : base("WorkTask")
        {
        }

        public override string Eval(string expr)
        {
            string strMacro;
            strMacro = GetExpr(expr);
            DateTime dtBDate = DateTime.Now;
            
            switch (strMacro)
            {
                case "Bdate":
                    strMacro = string.Format("{0:yyyy-MM-dd}", dtBDate);
                    break;
                case "FirstDayofYear":
                    strMacro = string.Format("{0}-1-1", dtBDate.Year);
                    break;
                case "LastDayofYear":
                    strMacro = string.Format("{0}-12-31", dtBDate.Year);
                    break;
                case "FirstDayofMonth":
                    strMacro = string.Format("{0}-{1}-1", dtBDate.Year, dtBDate.Month);
                    break;
                case "LastDayofMonth":
                    DateTime dtTemp = dtBDate.AddMonths(1);
                    dtTemp = dtTemp.AddDays(1 - dtTemp.Day);
                    strMacro = string.Format("{0:yyyy-MM-dd}", dtTemp);
                    break;
                case "Year":
                    strMacro = string.Format("{0}",dtBDate.Year);
                    break;
                case "Month":
                    strMacro = string.Format("{0}", dtBDate.Month);
                    break;
                case "Day":
                    strMacro = string.Format("{0}", dtBDate.Day);
                    break;
                default:
                    strMacro = "";
                    break;
            }


            return strMacro;

            //throw new NotImplementedException();
        }
    }
}
